package com.neuedu.dao;

import com.neuedu.pojo.Admin;
import com.neuedu.utils.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class LoginDaoImpl implements ILoginDao {
    @Override
    public Admin login(Admin admin) {
        Admin admin1 = new Admin();
        PreparedStatement ps = null;
        Connection connection = DBUtil.getConnection();
        ResultSet rs = null;
        String sql = "select * from users where username=? and password=?";
        try {
            ps = connection.prepareStatement(sql);
            ps.setString(1, admin.getUsername());
            ps.setString(2, admin.getPassword());
            rs = ps.executeQuery();
            while (rs.next()) {

                admin1.setUsername(rs.getString("username"));
                admin1.setPassword(rs.getString("password"));
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(ps, connection);

        }
        return admin1;
    }
}
